package com.dqx.opengl_es_demo;

import android.app.ActivityManager;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ConfigurationInfo;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

import com.dqx.opengl_es_demo.camera.CameraActivity;
import com.dqx.opengl_es_demo.circle.CircleActivity;
import com.dqx.opengl_es_demo.cone.ConeActivity;
import com.dqx.opengl_es_demo.cube.CubeActivity;
import com.dqx.opengl_es_demo.cylinder.CylinderActivity;
import com.dqx.opengl_es_demo.face.FaceDetectionActivity;
import com.dqx.opengl_es_demo.filter.FilterActivity;
import com.dqx.opengl_es_demo.model.ModelActivity;
import com.dqx.opengl_es_demo.sphere.SphereActivity;
import com.dqx.opengl_es_demo.square.SquareActivity;
import com.dqx.opengl_es_demo.image.ImageActivity;
import com.dqx.opengl_es_demo.transform.TransformActivity;
import com.dqx.opengl_es_demo.triangle.TriangleActivity;
import com.dqx.opengl_es_demo.triangle2.Triangle2Activity;

public class MainActivity extends AppCompatActivity implements AdapterView.OnItemClickListener {
    ListView listView;
    ArrayAdapter<String> adapter;
    String[] list = new String[]{"三角形（不使用投影和相机）", "三角形（使用投影和相机）",
            "正方形", "绘制圆", "立方体", "圆锥体", "圆柱体", "球",
            "纹理图片", "图像过滤处理", "平移、旋转和缩放", "摄像机",
            "3D模型","人脸识别"
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        if (!isSupportsEs2()) {
            Toast.makeText(this, "该设备不支持OpenGL ES2.0功能",
                    Toast.LENGTH_SHORT).show();
            return;
        }

        listView = findViewById(R.id.list_view);
        adapter = new ArrayAdapter<>(this, R.layout
                .support_simple_spinner_dropdown_item, list);
        listView.setAdapter(adapter);
        listView.setOnItemClickListener(this);
    }

    /**
     * 判断是否支持OpenGL-ES 2.0版本
     *
     * @return
     */
    public boolean isSupportsEs2() {
        ActivityManager activityManager = (ActivityManager)
                getSystemService(Context.ACTIVITY_SERVICE);
        ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
        return configurationInfo.reqGlEsVersion >= 0x20000;
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        Intent intent = null;
        switch (position) {
            case 0:
                intent = new Intent(this, TriangleActivity.class);
                break;
            case 1:
                intent = new Intent(this, Triangle2Activity.class);
                break;
            case 2:
                intent = new Intent(this, SquareActivity.class);
                break;
            case 3:
                intent = new Intent(this, CircleActivity.class);
                break;
            case 4:
                intent = new Intent(this, CubeActivity.class);
                break;
            case 5:
                intent = new Intent(this, ConeActivity.class);
                break;
            case 6:
                intent = new Intent(this, CylinderActivity.class);
                break;
            case 7:
                intent = new Intent(this, SphereActivity.class);
                break;
            case 8:
                intent = new Intent(this, ImageActivity.class);
                break;
            case 9:
                intent = new Intent(this, FilterActivity.class);
                break;
            case 10:
                intent = new Intent(this, TransformActivity.class);
                break;
            case 11:
                intent = new Intent(this, CameraActivity.class);
                break;
            case 12:
                intent = new Intent(this, ModelActivity.class);
                break;
            case 13:
                intent = new Intent(this, FaceDetectionActivity.class);
                break;
        }
        startActivity(intent);
    }
}
